package com.hyg.lib_base.Net;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import org.greenrobot.eventbus.EventBus;


public class BrokenNetReceiver extends BroadcastReceiver {

//    private SweetAlertDialog pDialog;
    private static final String TAG = "NetworkConnectChanged";

    @Override
    @SuppressLint("NewApi")
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.

        boolean isConnected = NetworkUtils.isConnected(context);
                Log.d(TAG, "onReceive: 当前网络 " + isConnected);
        EventBus.getDefault().post(new NetworkChangeEvent(isConnected));

//        ConnectivityManager connectivity = (ConnectivityManager) context
//                .getSystemService(Context.CONNECTIVITY_SERVICE);
//        NetworkCapabilities networkCapabilities = connectivity.getNetworkCapabilities(connectivity.getActiveNetwork());
//        Log.i("Avalible", "NetworkCapalbilities:" + networkCapabilities.toString());


    }
//
//    public void Dialog(final Context context) {
//        if (!pDialog.isShowing()) {
//            pDialog = new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE);
//            pDialog.setTitleText("提示");
//            pDialog.setContentText("当前网络不可用，请检查下您的网络");
//            pDialog.setConfirmButton("去设置", new SweetAlertDialog.OnSweetClickListener() {
//                public void onClick(SweetAlertDialog sweetAlertDialog) {
//                    sweetAlertDialog.cancel();
//                    context.startActivity(new Intent("android.net.wifi.PICK_WIFI_NETWORK"));
//                }
//            });
//            pDialog.setCancelButton("知道啦", new SweetAlertDialog.OnSweetClickListener() {
//                public void onClick(SweetAlertDialog sweetAlertDialog) {
//                    sweetAlertDialog.cancel();
//                }
//            });
//            pDialog.show();
//        }
//    }
}
